"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 系统内部使用工具
Case Name   : gs_ctl status使用-D指定正确数据库实例目录查看备机运行状态是否成功
Create At   : 2021/01/19
Owner       : opentestcase015
Description :
    1.gs_ctl status指定-D设置参数为正确的数据库实例目录
Expect      :
    1.gs_ctl status指定-D设置参数为正确的数据库实例目录成功
History     :
    Modified by opentestcase027 2023/1/12: 优化用例步骤格式及一主两备判断方式
"""

import unittest
import os
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH

LOG = Logger()
primary_sh = CommonSH('PrimaryDbUser')


@unittest.skipIf(3 != primary_sh.get_node_num(), '非1+2环境不执行')
class SystemInternalTools(unittest.TestCase):
    def setUp(self):
        LOG.info(f'--------{os.path.basename(__file__)} start--------')
        self.constant = Constant()
        self.sh_standby = CommonSH('Standby1DbUser')

    def test_system_internal_tools(self):
        LOG.info('--------step1:查看备机状态     expect:备机状态正常--------')
        msg = self.sh_standby.execute_gsctl(
            "status", self.constant.gs_ctl_status_running)
        self.assertTrue(msg)

    def tearDown(self):
        LOG.info('--------无需清理环境常--------')
        LOG.info(f'--------{os.path.basename(__file__)} end--------')
